import model

'***************************
'
'
Class ScoreStatusBar
	private
	Field value:Int = 0
	Field barValue:Float = 0
	Field increment:Float = 0
	Field img:GameImage
	Field valueTween:Tween2= New Tween2(Tween2.Cubic.EaseInOut,0,0,1000)
	Field star1:GameImage
	Field star2:GameImage
	Field star3:GameImage
	Field star1Value:Float=0
	Field star2Value:Float=0
	Field star3Value:Float=0
	Field star1Rotate:Int=0
	Field star2Rotate:Int=0
	Field star3Rotate:Int=0
	Field star1Scale:Float=0
	Field star2Scale:Float=0
	Field star3Scale:Float=0
	
	Field starDanceFadeTween:Tween2= New Tween2(Tween2.Cubic.EaseInOut,0.75,1.25,500)
	
	public
	Const STARS_MAX:Int = 3
	Field x:Int = 0
	Field y:Int = 0
	Field width:Int = 0
	Field width2:Float = 0
	Field height:Float = 0
	Field pointsToMax:Float = 12 ' Best if this is divisible by 3
	
	Method New(x:Int, y:Int, height:Int,pointsToMax:Int )
		self.x = x
		self.y = y	
		self.height = height		
		self.pointsToMax = pointsToMax
		increment=height/pointsToMax
		img = game.images.Find("scoreBar")
		self.width = img.w
		self.width2 = width/2
		
		img.MidHandle(false)
		star1 = game.images.Find("collectStar")
		star2 = game.images.Find("collectStar")
		star3 = game.images.Find("collectStar")
		star1Value = pointsToMax/3
		star2Value = (pointsToMax/3)*2
		star3Value =  (pointsToMax/3)*3
		
		starDanceFadeTween.SetYoYo(true)
		starDanceFadeTween.SetLooping(true)
		starDanceFadeTween.Start()
	End
	
	Method Reset:Void()
		value = 0
	End
	
	Method AddPoints:void()
		value += 1
		
		if(value>pointsToMax)
			value = pointsToMax
		End
		
		valueTween.SetValue(barValue,value)
		valueTween.Start()
	End
	
	Method SubtractPoints:void()
		value -= 1
		
		if (value<0)
			value = 0
		End		
		
		valueTween.SetValue(barValue,value)
		valueTween.Start()
	End
	
	Method GetSelectedStars:Int()
		Local count:Int =0
		
		if(barValue>=star1Value)
			count +=1
		endif
		
		if(barValue>=star2Value)
			count +=1
		endif
		
		if(barValue>=star3Value)
			count +=1
		endif
		
		return count
	End
	
	Method Update:Void()
		starDanceFadeTween.Update()
		valueTween.Update()		
	End
	
	Method Draw:Void()
		SetColor(0,0,0)
		DrawRect(x,y, width+2, height)
		
		SetColor(255,255,255)
		barValue = valueTween.Value()
		DrawBar(x+1,y+height-(barValue*increment)-1, barValue*increment)
		
		'
		' stars
		'		
		if(barValue>=star1Value)
		 	SetColor(255,255,255)			
			star1Rotate+=2
			star1Scale=starDanceFadeTween.Value()						
		else
			SetColor(100,100,100)
			star1Rotate=0
			star1Scale=1					
		endif
	
		star1.Draw(x+width2, y+height-(star1Value*increment),star1Rotate, star1Scale, star1Scale, 0)
		
		if(barValue>=star2Value)
		 	SetColor(255,255,255)
			star2Rotate+=2
			star2Scale=starDanceFadeTween.Value()
		else
			SetColor(100,100,100)
			star2Rotate=0
			star2Scale=1
		endif
		star2.Draw(x+width2, y+height-(star2Value*increment),star2Rotate, star2Scale, star2Scale, 0)
		
		if(barValue>=star3Value)
		 	SetColor(255,255,255)
			star3Rotate+=2
			star3Scale=starDanceFadeTween.Value()
		else
			SetColor(100,100,100)
			star3Rotate=0
			star3Scale=1
		endif
		star3.Draw(x+width2, y+height-(star3Value*increment),star3Rotate, star3Scale, star3Scale, 0)
		
		SetColor(255,255,255)
	End
	
	Method DrawBar:void(x1#, y1#, barHeight#)
		PushMatrix()
		Translate(x1, y1)
		Scale(1, barHeight)
		img.Draw( 0, 0)
		PopMatrix()
	End
End